package pos.Driving.Train;

import javax.vecmath.Color3f;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;

/**
 *
 * @author plus
 */
public class TrainDesc {
    static final int TYPE_A=1,TYPE_B=2, TYPE_C=3;
    String Name, Band,Desc, DefColorMaterialName;
    Color3f DefColor;
    int Type, Carriages, DefaultLine,DoorsPerCarriage;
    float Length;

    public TrainDesc(String Name, String Band,String Desc,
            int Type, int Carriages, int DefaultLine, 
            String DefColorMaterialName, Color3f DefColor) {
        this.Name = Name;
        this.Band = Band;
        this.Type = Type;
        this.Desc = Desc;
        this.Carriages = Carriages;
        this.DefaultLine = DefaultLine;
        this.DefColorMaterialName=DefColorMaterialName;
        this.DefColor=DefColor;
        
        switch (Type){
            case TYPE_A:
                DoorsPerCarriage=5;
                break;
            case TYPE_B:
                DoorsPerCarriage=4;
                break;
            case TYPE_C:
                DoorsPerCarriage=4;
                break;
        }
    }
    
    public TrainDesc(Document doc){
        int r, g, b;
        XPathFactory xpfactory = XPathFactory.newInstance();
        XPath xpath = xpfactory.newXPath();
        try{
            this.Name = xpath.evaluate("/train/desc/name", doc).trim();
            this.Band = xpath.evaluate("/train/desc/band", doc).trim();
            this.Type = Integer.parseInt(xpath.evaluate("/train/desc/type", doc).trim());
            this.Desc = xpath.evaluate("/train/desc/desc", doc).trim();
            this.DefaultLine
                    = Integer.parseInt(xpath.evaluate("/train/desc/defaultLine", doc).trim());
            this.Length
                    = Float.parseFloat(xpath.evaluate("/train/desc/length", doc).trim());
            this.DefColorMaterialName
                    = xpath.evaluate("/train/desc/defColorMaterialName", doc).trim();
            r = Integer.parseInt(xpath.evaluate("/train/desc/defColor/r", doc).trim(),16);
            g = Integer.parseInt(xpath.evaluate("/train/desc/defColor/g", doc).trim(),16);
            b = Integer.parseInt(xpath.evaluate("/train/desc/defColor/b", doc).trim(),16);

            this.DefColor=new Color3f(r/255f,g/255f,b/255f);

        }catch(Exception e){
            e.printStackTrace();
        }
    }
    
}
